const mongoose = require('mongoose')
const crypto = require('crypto')
const { dbHost } = require('../../conf/index')
const { generateId } =require('../../utils/index')

const connection = mongoose.createConnection(`mongodb://${dbHost}/manage_db`)

const Schema = mongoose.Schema

const userSchema = new Schema({
  userNo:{type: String,default(){
    return generateId('XTYH')
  }},
  userPhone: { type: String, default: '' }, //电话
  userName: {
    type: String,
    default() {
      return crypto.randomUUID() //js自带的id生成
    }
  }, //昵称
  account: { type: String, required: true }, //账号
  password: { type: String, required: true }, //密码，真实密码
  sex: { type: Number, default: 1 }, //1代表男，0代表女
  img_url: { type: String, default: '' }, // 头像
  email:{type:String,default:''},
  status: { type: Number,default:1 }, // 状态，是否能登录1能登，0不能
  token: { type: String } 
})

module.exports = connection.model('user', userSchema)
